/**
 * 
 */
package kr.co.insoft.auth.service.mail.impl;

import java.util.HashMap;
import java.util.Map;

import kr.co.insoft.auth.model.mail.MaillingFormModel;
import kr.co.insoft.auth.model.members.JoinFormModel;
import kr.co.insoft.auth.repository.mail.VelocityEmailSender;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.scheduling.annotation.Async;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
public class RegistrationMail {

	final VelocityEmailSender velocityEmailSender;
	Map<String, Object> hTemplateVariables;
	SimpleMailMessage msg;

	public RegistrationMail(final VelocityEmailSender velocityEmailSender,
			final JoinFormModel joinFormModel,
			final MaillingFormModel maillingFormModel,
			final String systemSender, final String subject, final String authServerApiUrl) {
		this.velocityEmailSender = velocityEmailSender;

		hTemplateVariables = new HashMap<String, Object>();
		hTemplateVariables.put("username", joinFormModel.getNickname());
		hTemplateVariables.put("confirmKey", maillingFormModel.getConfirmKey());
		hTemplateVariables.put("authServerApiUrl", authServerApiUrl);
		msg = new SimpleMailMessage();
		msg.setFrom(systemSender);
		msg.setTo(joinFormModel.getUsername());
		msg.setSubject(subject);
	}

	@Async
	public void run() {
		velocityEmailSender.send(msg, hTemplateVariables);
	}
}
